package com.hmsm.sys.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

import com.hmsm.server.base.BaseAction;
import com.hmsm.server.common.CommonUtil;
import com.hmsm.sys.po.Menu;
import com.hmsm.sys.po.UserInfo;

@SuppressWarnings("serial")
public class IndexAction extends BaseAction<UserInfo> implements SessionAware {

	private static final Log log = LogFactory.getLog(IndexAction.class);
	
	private static String MAIN_MENU_KEY = "mainMenus";
	
	private Map<String, Object> session;
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public String getSysLogo() {
		String sysLogo = CommonUtil.getSysConfigMap().get("sysLogo");
		return sysLogo;
	}

	private List<Menu> menus;

	public List<Menu> getMenus() {
		return menus;
	}

	public String getDefinedResult(){
		return CommonUtil.imgViewVersion==null||CommonUtil.imgViewVersion.equals("")?"":CommonUtil.imgViewVersion==1?"-new":"-old";
	}
	
	public IndexAction(){
	}

	@Override
	public String execute() throws Exception {
		UserInfo currentUser = getSessionUser();
		if (currentUser==null){
//			return LOGIN;
		}
		return super.execute();
	}
	
	public String top(){
		
		return SUCCESS;
	}
	
	public String leftScroll(){
		
		return SUCCESS;
	}
	
	public String mainMenu(){
		UserInfo currentUser = getSessionUser();
		menus = (List<Menu>) session.get(MAIN_MENU_KEY);
		// 权限变更后应考虑刷新菜单，以后优化
		if(menus==null){
			try {
				menus = getMenuService().getMainMenus(currentUser);
			} catch (Exception e) {
				e.printStackTrace();
			}
			session.put(MAIN_MENU_KEY, menus);
		}
		return SUCCESS;
	}
	
	public String welcome(){
		return SUCCESS;
	}
	
}
